<%@ page import="canglang.monitor.core.base.converter.DateConverter" %>
<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<codelookup:codeCollection id="accessTypeList" codeType="CODE_TYPE" filterName="CODE_FILTER"
                           filterParams="ACCESS_TYPE"/>
<script type="text/javascript">
function genereateReport() {
    $("td").removeClass("showErrorClass");
    
    var currentForm = document.forms["searchReportForm"];
    var caseType = currentForm.elements["searchTO.caseType"];
    if (caseType.value != 1 && caseType.value != 3)
    {
        $(caseType).parents("tr:first").find("td:first").addClass("showErrorClass");
        addErrorXHTML(caseType, $(caseType).parents("tr:first").find("td:first").text() + '<s:text name="label.reports.select.invalidcasetype"/>');
        return false;
    }

    var reportType = currentForm.elements["searchTO.reportType"];

    var checkvalue;
    var isChecked = false;

    for (var i = 0; i < reportType.length; i++)
    {
        if (reportType[i].checked)
        {
            isChecked = true;
            checkvalue = reportType[i].value;
        }
    }

    if (!isChecked)
    {
        alert('<s:text name="label.reports.select.atleast.onefunctioin.record"/>');
        return false;
    } else
    {
        if (checkvalue == 'age')
        {
            var ageStr = currentForm.elements["searchTO.ageStr"];
            if (ageStr.value == "")
            {
                alert('<s:text name="label.reports.age.empty"/>');
                return false;
            } else
            {
                currentForm.elements["searchTO.ageStr"].value=ageStr.value.trim();
                var agess = (ageStr.value.trim()).split(",");
                if (agess.length==1)
                {
                    alert('<s:text name="label.reports.age.invalid"/>');
                    return false;
                }
                var temp=0;
                for (var i = 0; i < agess.length; i++)
                {
                    if(!validateForm_numbervalue(agess[i]))
                   {
                       alert('<s:text name="label.reports.age.invalid"/>');
                       return false;
                   }
                   if (parseFloat(temp)>=parseFloat(agess[i].trim())&&i>0)
                   {
                        alert('<s:text name="label.reports.age.invalid"/>');
                        return false;
                   }
                   temp=agess[i];
                }
            }
        }
        if (checkvalue == 'invAmount')
        {
            var invAmountStr = currentForm.elements["searchTO.invAmountStr"];
            if (invAmountStr.value == "")
            {
                alert('<s:text name="label.reports.amount.empty"/>');
                return false;
            } else
            {
                currentForm.elements["searchTO.invAmountStr"].value=invAmountStr.value.trim();
                var amountss = (invAmountStr.value.trim()).split(",");
                if (amountss.length==1)
                {
                    alert('<s:text name="label.reports.amount.invalid"/>');
                    return false;                                                         
                }
                var temp=0;
                for (var i = 0; i < amountss.length; i++)
                {
                   if(!validateForm_numbervalue(amountss[i]))
                   {
                       alert('<s:text name="label.reports.amount.invalid"/>');
                       return false;
                   }
                   if (parseFloat(temp)>=parseFloat(amountss[i].trim())&&i>0)
                   {
                        alert('<s:text name="label.reports.amount.invalid"/>');
                        return false;
                   }

                   temp=amountss[i];
                }
            }
        }
    }


    submitForm("searchReportForm", "generateImage.action");

    return false;
}
function clickAgeText()
{
    var currentForm = document.forms["searchReportForm"];
    var invAmountStr = currentForm.elements["searchTO.invAmountStr"];
    var reportType = currentForm.elements["searchTO.reportType"];
    reportType[0].checked=true;
    invAmountStr.value="";
}
function clickAmountText()
{
     var currentForm = document.forms["searchReportForm"];
     var ageStr = currentForm.elements["searchTO.ageStr"];
     var reportType = currentForm.elements["searchTO.reportType"];
     ageStr.value="";
    reportType[5].checked=true;
}
function clearAllCheck()
{

        var currentForm = document.forms["searchReportForm"];
        var reportType = currentForm.elements["searchTO.reportType"];

        var ageStr = currentForm.elements["searchTO.ageStr"];
        var invAmountStr = currentForm.elements["searchTO.invAmountStr"];
        ageStr.value="";
        invAmountStr.value="";
        for (var i = 0; i < reportType.length; i++)
        {
           reportType[i].checked=false;
        }
}
function clearCheck()
{
    var currentForm = document.forms["searchReportForm"];
    var reportType = currentForm.elements["searchTO.reportType"];

    var checkvalue;
    var isChecked = false;

    for (var i = 0; i < reportType.length; i++)
    {
        if (reportType[i].checked)
        {
            isChecked = true;
            checkvalue = reportType[i].value;
        }
    }
    var ageStr = currentForm.elements["searchTO.ageStr"];
    var invAmountStr = currentForm.elements["searchTO.invAmountStr"];
    if (isChecked)
    {

        if (checkvalue == 'age')
        {
          invAmountStr.value="";
        }else if (checkvalue == 'invAmount')
        {
            ageStr.value="";
        }else
        {
            ageStr.value="";
             invAmountStr.value="";
        }
    }
}
function validateForm_numbervalue(s)
{
    if (isEmpty(s)) return false;
    return isInteger(s);
}

function displayCaseOneDiv(display) {
    if (display)
    {
        document.getElementById("caseOne1").style.display = "";
       // document.getElementById("caseOne2").style.display = "";
        document.getElementById("caseOne3").style.display = "";
        document.getElementById("caseOne4").style.display = "";
        document.getElementById("caseOne5").style.display = "";
        document.getElementById("caseOne6").style.display = "";
//        document.getElementById("caseOne7").style.display = "";


    }
}
function displayCaseThreeDiv(display) {
    if (display)
    {
        document.getElementById("caseOne1").style.display = "";
        //document.getElementById("caseOne2").style.display = "";
        document.getElementById("caseOne3").style.display = "";
        document.getElementById("caseOne4").style.display = "";
        document.getElementById("caseOne5").style.display = "";
        document.getElementById("caseOne6").style.display = "none";
//        document.getElementById("caseOne7").style.display = "none";
    }
}

function displayDiv(display) {

    document.getElementById("caseOne1").style.display = "none";
    //document.getElementById("caseOne2").style.display = "none";
    document.getElementById("caseOne3").style.display = "none";
    document.getElementById("caseOne4").style.display = "none";
    document.getElementById("caseOne5").style.display = "none";
    document.getElementById("caseOne6").style.display = "none";
//    document.getElementById("caseOne7").style.display = "none";
}

function showcase(isLoad) {
    clearErrorMessages();
     $("td").removeClass("showErrorClass"); 
    var casetType = document.getElementById("searchTO.caseType").value;
    if (casetType == '01')
    {
        displayCaseOneDiv(true);
    } else if (casetType == '03')
    {
        displayCaseThreeDiv(true);
    } else
    {
        displayDiv(false);
    }


    if (isLoad)
    {
         document.getElementById("caseImage").style.display = "";
    }else
    {
        document.getElementById("caseImage").style.display = "none";
        clearAllCheck();
    }
    //clearAllCheck();
    //clearCheck();
}

function back() {
    submitForm("searchReportForm", "../cases/clientSummary.action");
}


</script>
<div id='searchReportFormDiv'>
<s:form name="searchReportForm" action="">
<table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
<tr>
    <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
        <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
    </td>
    <td valign="bottom" class="page_title_bg" width="96%"><span class="page_title"><s:text
            name="label.imgreport"/></span></td>
</tr>
<tr>
<td class="subcontent">&nbsp;</td>
<td class="subcontent">
<table class="sectionBorder" width="100%">
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.dateFrom'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <monitor:date name="searchTO.startDateAsStr"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.dateTo'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <monitor:date name="searchTO.endDateAsStr"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.case.select.title'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="form_label_padded" width="100%" nowrap>
        <s:select list="#attr.accessTypeList" name="searchTO.caseType" listKey="codeId" listValue="codeDesc"
                  onchange="showcase(false)"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="100%" colspan="3" id="caseOne1">
        <s:set name="aa" value="searchTO.reportType"/>
        <s:if test="#aa=='' or  #aa==null or #aa != 'age'">
            <input type="radio" name="searchTO.reportType" value="age" onclick="clearCheck();" ><s:text name='label.caseone.age'/><s:textfield
                name="searchTO.ageStr" maxlength="50" onclick="clickAgeText();"/> <s:text name="label.reports.age.sample"/>
        </s:if>
        <s:if test="#aa == 'age'">
            <input type="radio" name="searchTO.reportType" value="age" checked  onclick="clearCheck();"><s:text
                name='label.caseone.age'/><s:textfield name="searchTO.ageStr" maxlength="50" onclick="clickAgeText();"/> <s:text name="label.reports.age.sample"/>
        </s:if>

    </td>
</tr>
<tr>
    <td class="form_label_padded" width="100%" colspan="3" id="caseOne3">
        <s:if test="#aa=='' or  #aa==null or #aa != 'rank'">
            <input type="radio" name="searchTO.reportType" value="rank"  onclick="clearCheck();"><s:text name='label.caseone.rank'/>
        </s:if>
        <s:if test="#aa == 'rank'">
            <input type="radio" name="searchTO.reportType" value="rank" checked  onclick="clearCheck();"><s:text name='label.caseone.rank'/>
        </s:if>

    </td>
</tr>
<tr>
    <td class="form_label_padded" width="100%" colspan="3" id="caseOne4">
        <s:if test="#aa=='' or  #aa==null or #aa != 'industry'">
            <input type="radio" name="searchTO.reportType" value="industry"  onclick="clearCheck();"><s:text name='label.caseone.industry'/>
        </s:if>
        <s:if test="#aa == 'industry'">
            <input type="radio" name="searchTO.reportType" value="industry" checked  onclick="clearCheck();"><s:text
                name='label.caseone.industry'/>
        </s:if>

    </td>
</tr>
<tr>
    <td class="form_label_padded" width="100%" colspan="3" id="caseOne5">
        <s:if test="#aa=='' or  #aa==null or #aa != 'hotInd'">
            <input type="radio" name="searchTO.reportType" value="hotInd"  onclick="clearCheck();"> <s:text name='label.caseone.hotInd'/>
        </s:if>
        <s:if test="#aa == 'hotInd'">
            <input type="radio" name="searchTO.reportType" value="hotInd" checked  onclick="clearCheck();"><s:text name='label.caseone.hotInd'/>
        </s:if>

    </td>
</tr>
<tr>
    <td class="form_label_padded" width="100%" colspan="3" id="caseOne6">
        <s:if test="#aa=='' or  #aa==null or #aa != 'invAmount'">
            <input type="radio" name="searchTO.reportType" value="invAmount"  onclick="clearCheck();"><s:text
                name='label.caseone.invAmount'/><s:textfield name="searchTO.invAmountStr" maxlength="50" onclick="clickAmountText()"/> <s:text name="label.reports.amount.sample"/>
        </s:if>
        <s:if test="#aa == 'invAmount'">
            <input type="radio" name="searchTO.reportType" value="invAmount" checked  onclick="clearCheck();"> <s:text
                name='label.caseone.invAmount'/><s:textfield name="searchTO.invAmountStr" maxlength="50" onclick="clickAmountText()"/>  <s:text name="label.reports.amount.sample"/>
        </s:if>

    </td>
</tr>
<tr>
    <td class="txtData" colspan="6">
        <input type="button" class="button" value="<s:text name='label.reports.generate' />"
               onclick="genereateReport()">
        <input type="button" class="button" value="<s:text name='label.back'/>" onclick="back();">
    </td>
</tr>
<tr id="caseImage">
    <td class="txtData" colspan="6">


                 <s:set name="bb" value="searchTO.caseType"/>        
                    <s:if test="#bb!=null and #aa!=null">
                                            <img width="800" height="250" src="<s:url action="getBigPieImgFromByte">
                                                                  <s:param name="searchTO.caseType" value="searchTO.caseType"/>
                                                                  <s:param name="searchTO.reportType" value="searchTO.reportType"/>
                                                                  <s:param name="searchTO.ageStr" value="searchTO.ageStr"/>
                                                                  <s:param name="searchTO.invAmountStr" value="searchTO.invAmountStr"/>
                                                                  <s:param name="searchTO.startDateAsStr" value="searchTO.startDateAsStr"/>
                                                                  <s:param name="searchTO.endDateAsStr" value="searchTO.endDateAsStr"/>
                                                                 </s:url>">
                                            <img width="800" height="250" src="<s:url action="getBigColumnImgFromByte">
                                                                <s:param name="searchTO.caseType" value="searchTO.caseType"/>
                                                                  <s:param name="searchTO.reportType" value="searchTO.reportType"/>
                                                                  <s:param name="searchTO.ageStr" value="searchTO.ageStr"/>
                                                                  <s:param name="searchTO.invAmountStr" value="searchTO.invAmountStr"/>
                                                                  <s:param name="searchTO.startDateAsStr" value="searchTO.startDateAsStr"/>
                                                                  <s:param name="searchTO.endDateAsStr" value="searchTO.endDateAsStr"/>
                                                                 </s:url>">
                    </s:if>


    </td>
</tr>
</table>
</td>
</tr>
</table>
<script type="text/javascript">
    showcase(true);
</script>
</s:form></div>                                                                                                         
